<?php
//--------------------------------------------------
//	Filename: profile.php
//--------------------------------------------------
// Information:
// This file shows the user-profile page. 
//--------------------------------------------------
if( !defined('IN_INDEX') )
{
	printError("ACCESS DENIED", "This page is hidden.");
	exit;
}
include('inc/functions_gym.php');
include('inc/functions_award.php');

$catname = @$_REQUEST['cat'];
$gym_id = @$_REQUEST['gym_id'];
if(!checkSession())
{
			function redirect($url)
			{
			?>
				<script type="text/javascript">
					{
					window.location = "<?=$url?>";
					}
				</script>
			<?php 
			}
			redirect("index.php?action=login");
	exit;
}
else
{
	if(isset($_REQUEST['id']))
	{
		$USER_PROFILE = new User('id', $_REQUEST['id']);
		
		if($catname == "")
		{
			$page_url = "index.php?action=profile&id=" . $_REQUEST['id'];
			if(isset($_REQUEST['gym_id']))
			{
				$page_url = "index.php?action=profile&id=" . $_REQUEST['id']."&gym_id=".$_REQUEST['gym_id'];
			}
		}
		else
		{
			$page_url = "index.php?action=profile&cat=". $catname ."&id=" . $_REQUEST['id'];
			if(isset($_REQUEST['gym_id']))
			{
				$page_url = "index.php?action=profile&cat=". $catname ."&id=" . $_REQUEST['id']."&gym_id=".$_REQUEST['gym_id'];
			}
		}
	}
	else
	{
		$USER_PROFILE = $USER;
		if($catname == "")
		{
			$page_url = "index.php?action=profile";
			if(isset($_REQUEST['gym_id']))
			{
				$page_url = "index.php?action=profile"."&gym_id=".$_REQUEST['gym_id'];
			}
		}
		else
		{	
			$page_url = "index.php?action=profile&cat=". $catname ."";
			if(isset($_REQUEST['gym_id']))
			{
				$page_url = "index.php?action=profile&cat=". $catname .""."&gym_id=".$_REQUEST['gym_id'];
			}
		}
	}
}
$dateformat = $CONFIG['date_format'];
$time = time();
include('inc/functions_blog.php');

if(!isset($_REQUEST['gym_id']))
{
	if($catname == "uncategorized")
	{
		$blogs = getTrainingList(" WHERE category='uncategorized' AND user_id='" . $USER_PROFILE->getId() . "' ORDER BY -date");
	}
	else if($catname == "")
	{
		$blogs = getTrainingList(" WHERE user_id='" . $USER_PROFILE->getId() . "' ORDER BY -date");
	}
	else
	{
		$blogs = getTrainingList(" WHERE category='". $catname ."' AND user_id='" . $USER_PROFILE->getId() . "' ORDER BY -date");
	}
}
else
{
	$blogs = getTrainingList(" WHERE gym_id='". $gym_id ."' AND user_id='" . $USER_PROFILE->getId() . "' ORDER BY -date");
}

$blog_archive = array();
foreach($blogs as $key => $val)
{
	$comments = getBlogComments(" WHERE post_type='training' AND post_id='" . $val['id'] . "'");
	$val['comments'] = count($comments);
	$blog_archive[] = array(
		'id' => $val['id'],
		'title' => $val['title'],
		'date' => (int) $val['date'],
		'comments' => $val['comments'],
	);
}
$archive_list = training_archive_list($blog_archive);
$friends_list = fetch_friends($USER->getId());
?>
<?php
if(isset($_GET['request']))
{
	$sql = "INSERT INTO user_friends SET ".
	"user_id='" . $USER->getId() . "', ".
	"friend_user_id='" . $_GET['request'] . "', ".
	"friend_status='pending'";
	if(!$result = $db->sql_query($sql))
	{
		printerror("SQL ERROR", mysql_error() ."<br />" . mysql_errno());
	}
	else
	{
		$friend_status = translate('friend_request_sendt');
		
		echo"<br /><br /><br /><br /><br /><br /><br /><br /><br />
		<center><meta http-equiv=\"refresh\"content=\"3;url=index.php?action=profile&id=". $USER_PROFILE->getId() ."\">";
		echo "<h2>" . $friend_status . "</h2>\n";
		echo "<br/>" . translate('redirectedin'). " <a href=\"index.php?action=profile&id=". $USER_PROFILE->getId() ."\">" . translate('clickhere') . "</a>.</center>
		<div class='fixed'>
					</div>
				</div>
				</div>
			<div class='fixed'>
			</div>
			<div id='footer'>
			<a id='gotop' href='#' onclick='MGJS.goTop();return false;'>" . translate('top') . "</a>
				<div align='center' id='copyright'>&copy; " . translate('copyrightyear') . " " . translate('header_text'). " - " .  translate('curversion') ." - <a href='index.php?action=contact'>" . translate('contact') ."</a> - <a href='index.php?action=about'>" . translate('about') . "</a> - " . translate('onlineusers'). ": " . getActiveUsers() . "<br />
                </div>";
		exit;
	}
}

if(isset($_REQUEST['id']) > 0)
{
// Counter
$ip = $_SERVER['REMOTE_ADDR']; 
$category = "user_profile";
$page = $_REQUEST['id']; 
$timenow = mktime();

//Check that the IP is not already listed for the current page 
$viewer_check_query = "SELECT ip, category, page, time FROM counter WHERE ip = '$ip' AND category = '$category' AND page = '$page'"; 
$viewer_check_result = mysql_query($viewer_check_query); 
$viewer_check_numrows = mysql_num_rows($viewer_check_result); 
while($row = mysql_fetch_assoc($viewer_check_result)) {
    $time = $row['time'];
}
    //If numrows is equal to zero, then the user is new 
    if($viewer_check_numrows == 0){ 
        //Add the new entry 
        $viewer_new_query = "INSERT INTO counter (ip, category, page, time) VALUES 
        ('$ip', '$category', '$page', '$timenow')"; 
        $viewer_new_result = mysql_query($viewer_new_query); 
    } 
	//Timeout of 1 hours before same ip can add one new hit
	elseif((time() - $time) > 3600 ){ 
        //Add the new entry 
        $viewer_new_query = "INSERT INTO counter (ip, category, page, time) VALUES 
        ('$ip', '$category', '$page', '$timenow')"; 
        $viewer_new_result = mysql_query($viewer_new_query); 
    } 

//Get the total number of viewers for this page 
$viewer_total_query = "SELECT * FROM counter WHERE category = '$category' AND page = '$page'"; 
$viewer_total_result = mysql_query($viewer_total_query); 
$viewer_total_numrows = mysql_num_rows($viewer_total_result);
}
?>
<!--
<script src="./jscript/prettyphoto/js/jquery-1.4.4.min.js" type="text/javascript" charset="utf-8"></script>
-->
<link rel="stylesheet" href="./jscript/prettyphoto/css/prettyPhoto.css" type="text/css" media="screen" charset="utf-8" />
<script src="./jscript/prettyphoto/js/jquery.prettyPhoto.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript">
var years = new Array();
var month = new Array();
<?php
foreach($archive_list as $year_key => $year_list)
{
	echo "years[" . $year_key . "] = new Array();\n";
		
	foreach($year_list as $month_key => $month_list)
	{
		echo "years[". $year_key . "][" . ($month_key + 1) . "] = '';\n";
	}
}
?>
function nav_list(y, m)
{
	for(var a in years)
	{
    	element_y = document.getElementById('archive_' + a);
			element_y_text = document.getElementById('archive_' + a + '_text');
		if(a == y)
		{
			if(m == 0 && element_y.style.display == "block")
			{
				element_y.style.display="none";
				element_y_text.style.fontWeight="normal";
			}
			else
			{
				element_y.style.display="block";
				element_y_text.style.fontWeight="bold";
			}
		}
		else
		{
			element_y.style.display="none";
			element_y_text.style.fontWeight="normal";
		}
		for(var b in years[a])
		{
			element_m = document.getElementById('archive_' + a + '_' + b);
			element_m_text = document.getElementById('archive_' + a + '_' + b + '_text');
			if(a == y && b == m)
			{
				if(element_m.style.display == "block")
				{
					element_m.style.display="none";
					element_m_text.style.fontWeight="normal";
				}
				else
				{
					element_m.style.display="block";
					element_m_text.style.fontWeight="bold";
				}
			}
			else
			{
				element_m.style.display="none";
				element_m_text.style.fontWeight="normal";
			}
		}
	}
}

function set_default_nav()
{
	<?php
	echo "var this_month = " . date('n', $time) . ";";
	echo "var this_year = " . date('Y', $time) . ";";
	?>
	if(undefined===window.years[this_year])
	{
		// do nothing
	}
	else
	{
		element_y = document.getElementById('archive_' + this_year);
		element_y_text = document.getElementById('archive_' + this_year + '_text');
		element_y.style.display="block";
		element_y_text.style.fontWeight="bold";
		if(undefined===window.years[this_year][this_month])
		{
			// do nothing
		}
		else
		{
			element_m = document.getElementById('archive_' + this_year + '_' + this_month);
			element_m_text = document.getElementById('archive_' + this_year + '_' + this_month + '_text');
			element_m.style.display="block";
			element_m_text.style.fontWeight="bold";
		}
	}
}
</script>

<div id='postpath'>
		<a title="<?php echo translate('gotofrontpage'); ?>" href="index.php"><?php echo translate('home'); ?></a>
		 &gt; <a href="index.php?action=blogs" title='<?php echo translate('showallblogs'); ?>'><?php echo translate('blog'); ?></a> &gt; 
<a href="index.php?action=profile&amp;id=<?php echo $USER_PROFILE->getId(); ?>"><?php echo $USER_PROFILE->getFirstname() . " " . ucf($USER_PROFILE->getLastname()); ?></a>
</div>

<!-- Left column START -->
<div class="leftcol">

	<!-- Profile pic START-->
	<div style="text-align: center;">
		<?php
		if($USER_PROFILE->getAvatarpath() != "")
		{
			$profile_pic_path = $CONFIG['user_data_path'] . $USER_PROFILE->getId() . "/thumbl_" . $USER_PROFILE->getAvatarpath();
			$profile_pic_pathfull = $CONFIG['user_data_path'] . $USER_PROFILE->getId() . "/" . $USER_PROFILE->getAvatarpath();
			if(file_exists($profile_pic_path))
			{
				echo "<a href='". $profile_pic_pathfull ."' rel='prettyPhoto'><img src=\"" . $profile_pic_path . "\" alt=\"" . translate('profile_picture') . "\" /></a>\n";
			}
			else
			{
				echo $profile_pic_path;
			}
		}
		else
		{
			if($USER_PROFILE->getGender() == "female")
			{
				echo "<img src=\"" . $CONFIG['user_data_path'] . "profile_female.gif\" alt=\"" . translate('profile_picture') . "\" />\n";
			}
			else
			{
				echo "<img src=\"" . $CONFIG['user_data_path'] . "profile_male.gif\" alt=\"" . translate('profile_picture') . "\" />\n";
			}
			if($USER->getId() == $USER_PROFILE->getId())
			{
			echo "<a href='index.php?action=profile&sub=edit_personal'>[" . translate('addprofilepicture') . "]</a>";
			}
		}
		?>
	</div>
  <!-- Profile pic END-->
    
    <br />
    
    <div style="clear: both;">
    
    <!-- Display user posts  START -->
        <div style="float: left; clear: right; padding-right: 5px;"><img src="img/post.png" /></div><?php echo translate('posts'); ?>: <b><?php echo ucf($USER_PROFILE->getPosts()); ?></b>
    <!-- Display user posts  END -->
    
     <div style="clear: both;"></div>
        
        <!-- Display more info link START -->
        <a href="index.php?action=profile&amp;sub=info&amp;id=<?php echo $USER_PROFILE->getId(); ?>"><div style='float: left; clear: right; padding-right: 5px;'><img src='img/show_more.png' /></div><?php echo translate('showmoreinfo'); ?></a>
        <!-- Display more info link END -->
        
      <div style="clear: both;"></div>
        
    <!-- Display send pm to user START -->
    	<?php
		if(checkSession() && ($USER->getId() != $USER_PROFILE->getId()))
		{
			echo "<a href=\"index.php?action=profile&sub=pm_new&to=" . $USER_PROFILE->getID() . "\"><div style='float: left; clear: right; padding-right: 5px; padding-top: 1px;'><img src='img/pm_unread2.png' /></a></div><a href=\"index.php?action=profile&sub=pm_new&to=" . $USER_PROFILE->getID() . "\">" . translate('send_pm') . "</a><br />\n";
		}
		?>
     <!-- Display send pm to user END -->
	
    <br />
    
    <!-- Display friends START -->
    <?php
	$friends_list = subval_sort($friends_list,'firstname');
	$f_list = array('online' => array(), 'offline' => array(), 'pending' => array());
	$is_friend = false;
	foreach($friends_list as $k => $v)
	{
		$online_time = is_user_online($v['user_id']);
		if($v['status'] == 'pending')
		{
			$f_list['pending'][] = $friends_list[$k];
		}
		else
		{
			if($online_time['last_visit'] > 0)
			{
				$array = array('online_time' => $online_time['last_visit'], 'page' => $online_time['page']);
				$array = array_merge($friends_list[$k], $array);
				$f_list['online'][] = $array;
			}
			else
			{
				$f_list['offline'][] = $friends_list[$k];
			}
		}
		if($v['user_id'] == $USER_PROFILE->getId())
		{
			$is_friend = true;
		}
	}
	if(isset($USER) && $USER_PROFILE->getId() == $USER->getId())
	{
	?>
    <b><?php echo translate('friends_list'); ?><!-- Vise antall venner her--></b><br />
    <ul id="friends_list">
    <?php
	$friends_string = str_replace('VAR1', count($f_list['online']), translate('friends_online'));
	$friends_string = str_replace('VAR2', (count($f_list['online']) + count($f_list['offline'])), $friends_string);
	echo $friends_string . "<br />";
	
	/**
	foreach($f_list['pending'] as $k => $v)
	{
		$online_time = is_user_online($v['user_id']);
		$fullname = $v['firstname'] . " " . $v['lastname'];
		if(strlen($fullname) > 16)
		{
			$display_name = substr($fullname, 0, 16) . "...";
		}
		else
		{
			$display_name = $fullname;
		}
		echo "<li><img src=\"img/yellow_light.png\" alt=\"\"/> <a href=\"index.php?action=profile&id=" . $v['user_id'] . "\" title=\"" . translate('pending_friend_request') . "\" class=\"pending_user\">" . $display_name . "</a>";
		if(checkSession() && isset($USER))
		{
			if($v['sender_id'] != $USER->getId())
			{
				echo "<br /><a href=\"index.php?action=profile&sub=friends&accept=" . $v['id'] . "\" title=\"" . translate('accept_friend_long') . "\"><center><img src=\"img/accept.png\" alt=\"" . translate('accept_friend') . "\" /></a> <a href=\"index.php?action=profile&sub=friends&decline=" . $v['id'] . "\" title=\"" . translate('decline_friend_long') . "\"><img src=\"img/decline.png\" alt=\"" . translate('decline_friend') . "\" /></a></center>";
			}
		}
		echo"</li>";
	}
	**/
	echo '<br />';
	echo "<a href='index.php?action=profile&amp;sub=friends'><div style='float: left; clear: right; padding-right: 5px;'><img src='img/user_friends.png' /></div> " . translate('showallfriends') . "</a>";
	?>
    	</ul>
    <!-- Display friends END -->
    	<?php
		}
	?>
        <?php    
    if(!$is_friend && $USER_PROFILE->getId() != $USER->getId())
	{
		echo "<a href=\"index.php?action=profile&amp;id=". $USER_PROFILE->getId() ."&request=" . $USER_PROFILE->getId() . "\"><div style='float: left; clear: right; padding-right: 5px;'><img src='img/user_add.png' /></div>" . translate('send_friend_request') . "</a><br />";
	}
	?>
   <br />
   <?php if($USER_PROFILE->getId() != $USER->getId()): ?>
   		
		<?php 
			if(isset($_GET['following'])){
				if('add'== $_GET['following']){
					add_this_user_to_my_followList($USER_PROFILE->getId());
				}else{
					remove_this_user_to_my_followList($USER_PROFILE->getId());
				}
			}
		?>

		<?php echo ui_follow_this_user($USER_PROFILE->getId()); ?>
    <?php endif;?>
	<br />
	<!--
	<?php if(who_am_i()== 'ADMIN' || who_am_i()== 'MOD'): ?>
		<a href="javascript:void(0);" onclick="open_popup_gym_pending();"><div style='float: left; clear: both; padding-right: 5px;'><img src='img/house.png' /></div><?php echo translate('gym_pendding')." ( ".count_number_gyms_need_activate()." ) ";?></a>
	<?php endif;?>
	-->
     </div>
	 <!-- Tuandt -->
	 <b><?php echo translate('awards')?></b>
	 <div class="award-list" style="text-align: center; color: red;">
	<?php
		$awardList = getAllAward();
		if(count($awardList) > 0){
			while($awardItem = mysql_fetch_array($awardList)) 
			{
				if(isset($_REQUEST['id'])){
					$result = getAwardOfExercise($_REQUEST['id'], $awardItem);
				}else{
					$result = getAwardOfExercise($_SESSION['user_id'], $awardItem);
				}
				if($result){
	?>
		<div class="award-item" style="margin-top: 15px;">
			<?php
			if(isset($result['training_id'])){
			?>
			<a href="index.php?action=profile&sub=stats_awards">
			<img src="img/award_pic/<?php echo $awardItem['image'] ?>"/><br/>
			<span class="award-name"><?php echo $awardItem['award_name']."<br/>"; ?></span>
			</a>
			<?php
			}else{
			?>
			<img src="img/award_pic/<?php echo $awardItem['image'] ?>"/><br/>
			<span class="award-name"><?php echo $awardItem['award_name']."<br/>"; ?></span>
			<?php
			}
			?>
		</div>
	<?php
				}
			}
		}
	?>
	 </div>
</div>
<!-- Left column END -->

<div id="like_popup_view" style="display:none;"></div>

<!-- Center column START -->
<div class="midcol">

	    <!-- Display user country flag START -->
    <div style='float: left; clear: right; padding-right: 3px;'><img src="img/flags/24/<?php echo strtolower($USER_PROFILE->getCountry()); ?>.png" alt="<?php echo $USER_PROFILE->getCountry(); ?>" /></div>
    <!-- Display user country flag END -->
	
    <!-- Display Profile title and status START -->

    <h1><?php echo $USER_PROFILE->getFirstname() . " " . ucf($USER_PROFILE->getLastname()); ?></h1>

    <!-- <p>Status </p>-->
    <!-- Display Profile title and status END -->
    
    <br />
    
    <!-- DISPLAY RESTICTED VIEW START -->
    <?php
    	$view_blog = true;
		if($USER_PROFILE->getBlogPrivacy() == 1 && $USER->getId() != $USER_PROFILE->getId())
		{
				echo translate('thisbloghasrestrictedview');
				$view_blog = false;
			
		}
		
		if($USER_PROFILE->getBlogPrivacy() == 2 && $USER->getId() != $USER_PROFILE->getId() && checkFriendAccepted($USER_PROFILE->getId(), $USER->getId()) != "accepted")
		{
				echo translate('thisbloghasrestrictedview_friends');
				$view_blog = false;
		}

		if($view_blog)
		{ // restrict view START
			?>
    <!-- Display posts START -->
		<?php
		$blogs_per_page = 5;
		$start = 0;
		if(checkSession())
		{
			$blogs_per_page = $USER->getBlogsPerPage();
		}
		if(isset($_REQUEST['p']))
		{
			$start = ($_REQUEST['p'] * $blogs_per_page) - $blogs_per_page;
		}
		
		$end = $start + $blogs_per_page;
		if($end > count($blogs))
		{
			$end = count($blogs);
		}
		
		
		$counter = 0;
		$showing = 0;
		foreach($blogs as $key => $val)
		{
			if($counter >= $start && $counter < $end)
			{
				$BLOG = $val;
				//include('profile_show.php');
				$U_PROFILE = new User('id', $val['user_id']);
				$url_to_post = "index.php?action=profile&amp;sub=show&amp;tid=" . $BLOG['id'];
				$comments = getBlogComments(" WHERE post_type='training' AND post_id='" . $BLOG['id'] . "' ORDER BY -comment_date");
				$comments_text0 = str_replace('VAR1', count($comments), $LANG['post_comments0']);
				$comments_text1 = str_replace('VAR1', count($comments), $LANG['post_comments1']);
				$comments_text2 = str_replace('VAR1', count($comments), $LANG['post_comments2']);
		?>
<!-- Show all blog post START-->
<div class="post">
	<h2><a class="title" href="<?php echo $url_to_post; ?>" rel="bookmark"><?php echo $BLOG['title']; ?></a></h2>
	<div class="info">
    
		<span class="date">
		<?php echo formatDate($BLOG['date'], ''); ?>
        </span>
        
		<span class="author">
        <a href="index.php?action=profile&amp;id=<?php echo $U_PROFILE->getId(); ?>" title="<?php echo translate('postby'); ?> <?php echo $U_PROFILE->getFirstname() . " " . ucf($U_PROFILE->getLastname()); ?>"><?php echo $U_PROFILE->getFirstname() . " " . ucf($U_PROFILE->getLastname()); ?></a> 
        <?php 
		if($USER_PROFILE->getShowBw() == 1)
		{
        	echo "(" .r_nr2(calcFromKg($BLOG['bodyweight'])) . "" . $w_metric . ")";
        }
        else
		{
		}
		?>
        </span>
		
		&nbsp;
		<a href="javascript:void(0);" onclick="open_who_likes(<?php echo $BLOG['id'];?>);"><img src="./img/thumb_up.png" alt="<?php echo translate('like');?>" /></a><span class="like" rel="<?php echo $BLOG['id'];?>"> <?php echo count_numberOfPersons_like($USER_PROFILE->getId(), $BLOG['id']);?>
		<?php if(is_like($USER_PROFILE->getId(),$_SESSION['user_id'], $BLOG['id'])):?>
			<a href="javascript:void(0);" onclick="like_unlike('unlike',<?php echo $_SESSION['user_id'];?>,<?php echo $USER_PROFILE->getId();?>,<?php echo $BLOG['id'];?>);" ><?php echo translate('unlike');?></a>
		<?php else:?>
			<a href="javascript:void(0);" onclick="like_unlike('like',<?php echo $_SESSION['user_id'];?>,<?php echo $USER_PROFILE->getId();?>,<?php echo $BLOG['id'];?>);" ><?php echo translate('like');?></a>
		<?php endif;?>
		</span>
		
		<?php
        if(isset($USER) && $USER->getId() == $U_PROFILE->getId() or $USER->getRank() >= 5)
        {
        ?>
                <!-- Only for admins and blog owner-->
                <span class="editpost">
                <a href="index.php?action=profile&amp;id=<?php echo $U_PROFILE->getId(); ?>&amp;sub=editt&amp;tid=<?php echo $BLOG['id']; ?>" title="<?php echo translate('editp_sub'); ?>"><?php echo translate('editp'); ?></a>
                </span>
        <?php
        }
        ?>
        <?php
        if(count($comments) == 0)
		{
		?>
		<span class="comments"><a href="<?php echo $url_to_post; ?>" title="<?php echo $BLOG['title']; ?>"><?php echo ucf($comments_text0); ?></a></span>
       	<?php
		}
		?>
         <?php
        if(count($comments) == 1)
		{
		?>
		<span class="comments"><a href="<?php echo $url_to_post; ?>" title="<?php echo $BLOG['title']; ?>"><?php echo $comments_text1; ?></a></span>
       	<?php
		}
		?>
        <?php
        if(count($comments) >= 2)
		{
		?>
		<span class="comments"><a href="<?php echo $url_to_post; ?>" title="<?php echo $BLOG['title']; ?>"><?php echo $comments_text2; ?></a></span>
       	<?php
		}
		?>

<div class="fixed"></div>

		<!-- Show content in blog post -->
		<div class="content">
		<?php
        if($USER->getShowTrainingInBlog() == 1)
		{
        $prev_ex = 0;
        foreach($BLOG['lifts'] as $k => $v)
        {
            if($v['exercise_id'] != $prev_ex)
            {
                $prev_ex = $v['exercise_id']; 
               	echo "<b>" . ucf(translate(getExercisename($prev_ex))) . "</b><br />\n";
		
		// Get personal bests
		// 1 RM
		$currentpr = checkIfNewPr($v['kg'], 1, $v['exercise_id'], $BLOG['date'], $U_PROFILE->getId(), $BLOG['meet']);
		$currentpr_tid = checkIfNewPrTid($v['kg'], 1, $v['exercise_id'], $BLOG['date'], $U_PROFILE->getId(), $BLOG['meet']);
		// 2 RM
		$currentpr2 = checkIfNewPr($v['kg'], 2, $v['exercise_id'], $BLOG['date'], $U_PROFILE->getId(), $BLOG['meet']);
		$currentpr2_tid = checkIfNewPrTid($v['kg'], 2, $v['exercise_id'], $BLOG['date'], $U_PROFILE->getId(), $BLOG['meet']);
		// 3 RM
		$currentpr3 = checkIfNewPr($v['kg'], 3, $v['exercise_id'], $BLOG['date'], $U_PROFILE->getId(), $BLOG['meet']);
		$currentpr3_tid = checkIfNewPrTid($v['kg'], 3, $v['exercise_id'], $BLOG['date'], $U_PROFILE->getId(), $BLOG['meet']);
		
		// Show personal best on selected exercise
		if($USER->getShowPb() == 1)
		{
			if($currentpr != 0 || $currentpr2 != 0 || $currentpr3 != 0)
			{
				// Training
				if($BLOG['meet'] == 0)
				{
					// KG selected
					if($w_metric == "kg")
					{
						echo "<span style='font-size: x-small; color: grey;'>(";
						if($currentpr != 0)
						{ 
							echo "<a style='font-size: x-small; color: grey;' href='index.php?action=profile&sub=show&tid=" . $currentpr_tid . "'>1 RM = " . r_nr2(calcFromKg($currentpr)) . "" . $w_metric . "</a>";
						}
						if($currentpr != 0 && $currentpr2 != 0)
						{
							echo ", ";
						} 
						if($currentpr2 != 0)
						{
							 echo "<a style='font-size: x-small; color: grey;' href='index.php?action=profile&sub=show&tid=" . $currentpr2_tid . "'>2 RM = " .  r_nr2(calcFromKg($currentpr2)) . "" . $w_metric . "</a>";
						}
						if($currentpr != 0 || $currentpr2 != 0 && $currentpr3 != 0)
						{
							echo ", ";
						} 
						if($currentpr3 != 0)
						{
							echo "<a style='font-size: x-small; color: grey;' href='index.php?action=profile&sub=show&tid=" . $currentpr3_tid . "'>3 RM = " .  r_nr2(calcFromKg($currentpr3)) . "" . $w_metric . "</a>";
						}
						echo ")<br /></span>";
					}
					// LBS selected
					else
					{
						echo "<span style='font-size: x-small; color: grey;'>(";
						if($currentpr != 0)
						{ 
							echo "<a style='font-size: x-small; color: grey;' href='index.php?action=profile&sub=show&tid=" . $currentpr_tid . "'>1 RM = " . r_nr(calcFromKg($currentpr)) . "" . $w_metric . "</a>";
						}
						if($currentpr != 0 && $currentpr2 != 0)
						{
							echo ", ";
						} 
						if($currentpr2 != 0)
						{
							 echo "<a style='font-size: x-small; color: grey;' href='index.php?action=profile&sub=show&tid=" . $currentpr2_tid . "'>2 RM = " .  r_nr(calcFromKg($currentpr2)) . "" . $w_metric . "</a>";
						}
						if($currentpr != 0 || $currentpr2 != 0 && $currentpr3 != 0)
						{
							echo ", ";
						} 
						if($currentpr3 != 0)
						{
							echo "<a style='font-size: x-small; color: grey;' href='index.php?action=profile&sub=show&tid=" . $currentpr3_tid . "'>3 RM = " .  r_nr(calcFromKg($currentpr3)) . "" . $w_metric . "</a>";
						}
						echo ")<br /></span>";
					}
				}
				// Meet
				elseif($BLOG['meet'] == 1 || $BLOG['meet'] == 3)
				{
					if($w_metric == "kg")
					{
						echo "<span style='font-size: x-small; color: grey;'>
						(<a style='font-size: x-small; color: grey;' href='index.php?action=profile&sub=show&tid=" . $currentpr_tid . "'>1 RM = " .  r_nr2(calcFromKg($currentpr)) . "" . $w_metric . "</a>)
						<br /></span>";
					}
					else
					{
						echo "<span style='font-size: x-small; color: grey;'>
						(<a style='font-size: x-small; color: grey;' href='index.php?action=profile&sub=show&tid=" . $currentpr_tid . "'>1 RM = " .  r_nr(calcFromKg($currentpr)) . "" . $w_metric . "</a>)
						<br /></span>";
					}
				}
			}
		}
	
	}
	
	//If kg is selected
	if($w_metric == "kg")
	{
		if($USER->getSortKgReps() == 1)
		{
			// If marked as training
			if($BLOG['meet'] == 0)
			{
				// If a lift fail
				if($v['kg'] > 0 && $v['reps'] == 0)
				{
					if($USER->getShowWeightchange() == 1)
					{
						// Display set with red color
						echo "<span style='color: red;'><div style='float: left; clear: right;'><img src='img/bomb.png' alt='bomb' /></div>" . r_nr2(calcFromKg($v['kg'])) . "" . $w_metric . "</span> <span style='color: red;'>x</span> <span style='color: red;'>" . $v['reps'] . " </span> ";
						
						// Display RPE
						if($v['rpe'] > 0)
						{
							echo "<span style='color: red;'> @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: red;' rel='prettyPhoto'>RPE</a></span> ";
						}
					}
					else
					{
						// Display set with red color
						echo "<span style='color: red;'>" . r_nr2(calcFromKg($v['kg'])) . "" . $w_metric . "</span> <span style='color: red;'>x</span> <span style='color: red;'>" . $v['reps'] . "</span> ";
						
						// Display RPE
						if($v['rpe'] > 0)
						{
							echo "<span style='color: red;'> @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: red;' rel='prettyPhoto'>RPE</a></span> ";
						}
					}
				}
				elseif($v['reps'] >= 1)
				{
					// Check if the user wants to show weightchanges
					if($USER->getShowWeightchange() == 1)
					{
						// Find the first set
						$check_first_set = checkIfWeightChangeOnSetsIsFirstSet($val['id'],$v['exercise_id']);
						
						if($check_first_set != $v['id'])
						{
								// Lifted at previous set
								$prev_weight = checkWeightChangeOnSets($val['id'],$v['id'],$v['exercise_id']);
								
								// Difference from the previous set
								$diff_prev = r_nr2(calcFromKg($v['kg']))-r_nr2(calcFromKg($prev_weight));
								
								// Display increase or deacrease
								if($diff_prev == 0)
								{
									// Same weight
									echo "<span style='color: lightblue; font-size: 0.8em;'><div style='float: left; clear: right;'><img src='img/arrow_right_blue.png' alt='same' /></div></span> ";
								}
								elseif($diff_prev > 0)
								{
									// Increase
									echo "<span style='color: green; font-size: 0.8em;'><div style='float: left; clear: right;'><img src='img/arrow_up_green.png' alt='increase' /></div>+" . $diff_prev . $w_metric ."</span> ";
								}
								elseif($diff_prev < 0)
								{
									// Deacrease
									echo "<span style='color: red; font-size: 0.8em;'><div style='float: left; clear: right;'><img src='img/arrow_down_red.png' alt='decrease' /></div>" . substr_replace($diff_prev,"", 0,0) . $w_metric ."</span> "; 
								}
						}
						else
						{
							// First set
							echo "<span style='color: lightblue; font-size: 0.8em;'><div style='float: left; clear: right;'><img src='img/arrow_right_green.png' alt='first' /></div></span> ";
						}
					}
					
					// Display set with null kg only repetitions
					if($v['kg'] == 0 && $v['type'] == "")
					{
						echo $v['reps'] . " "; 
						if($v['reps'] == 1) 
						{ 
							echo translate('repetition'); 
							if($v['rpe'] > 0)
							{
								echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
							}
						}
						elseif($v['reps'] > 1)
						{
							echo translate('repetitions');
							if($v['rpe'] > 0)
							{
								echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
							}
						}
					}
					// Display normal set
					elseif($v['type'] == "")
					{
						echo "" . r_nr2(calcFromKg($v['kg'])) . "" . $w_metric . " x " . $v['reps'] . "";
						
						// Display RPE
						if($v['rpe'] > 0)
						{
							echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
						}
					}
					// Display dropset
					elseif($v['type'] == "dropset")
					{
						$checkset = checkPreviouesSet($val['id'], $v['id'], $v['type_nr'], $v['exercise_id']);
						$checkset2 = checkPreviouesSet2($val['id'], $v['id'], $v['type_nr'], $v['exercise_id']);
						$checkset3 = checkPreviouesSet3($val['id'], $v['id'], $v['type_nr'], $v['exercise_id']);
						$checkset4 = checkPreviouesSet4($val['id'], $v['id'], $v['type_nr'], $v['exercise_id']);
						$checkset5 = checkPreviouesSet5($val['id'], $v['id'], $v['type_nr'], $v['exercise_id']);
															
						if($checkset == "dropset")
						{
							echo "<span style='padding-left:8px'></span>";
						}
						if($checkset2 == "dropset")
						{
							echo "<span style='padding-left:8px'></span>";
						}
						if($checkset3 == "dropset")
						{
							echo "<span style='padding-left:8px'></span>";
						}
						if($checkset4 == "dropset")
						{
							echo "<span style='padding-left:8px'></span>";
						}
						if($checkset5 == "dropset")
						{
							echo "<span style='padding-left:8px'></span>";
						}
						
						echo "" . r_nr2(calcFromKg($v['kg'])) . "" . $w_metric . " x " . $v['reps'];
						
						// Display RPE
						if($v['rpe'] > 0)
						{
							echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
						}
						
						echo " <i>(" . translate('dropset') . ""; if($v['type_nr'] != 0) { echo " " . $v['type_nr']; } echo ")</i>";
					}
					// Display superset with 0 kg
					elseif($v['type'] == "superset" && $v['kg'] == 0)
					{
					echo $v['reps'] . " "; 
					
						if($v['reps'] == 1) 
						{ 
							echo translate('repetition');
							
							// Display RPE
							if($v['rpe'] > 0)
							{
								echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
							}
							
							echo " <i>(" . translate('superset') . ""; if($v['type_nr'] != 0) { echo " " . $v['type_nr']; } echo ")</i> "; 
						}
						elseif($v['reps'] > 1)
						{
							echo translate('repetitions');
							
							// Display RPE
							if($v['rpe'] > 0)
							{
								echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
							}
							
							echo " <i>(" . translate('superset') . ""; if($v['type_nr'] != 0) { echo " " . $v['type_nr']; } echo ")</i> ";
						}
					}
					// Display normal superset
					elseif($v['type'] == "superset")
					{
						echo "" . r_nr2(calcFromKg($v['kg'])) . "" . $w_metric . " x " . $v['reps'];
						
						// Display RPE
						if($v['rpe'] > 0)
						{
							echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
						}
						
						echo " <i>(" . translate('superset') . ""; if($v['type_nr'] != 0) { echo " " . $v['type_nr']; } echo ")</i> ";
					}
				}
			}
			// If marked as meet
			elseif($BLOG['meet'] == 1 || $BLOG['meet'] == 3)
			{
				if($v['reps'] == 1)
				{
					echo r_nr2(calcFromKg($v['kg'])) . "" . $w_metric;
				}
				elseif($v['reps'] == 0)
				{
					echo "<span style='text-decoration: line-through;'>" . r_nr2(calcFromKg($v['kg'])) . "" . $w_metric . "</span>";
				}
				elseif($v['reps'] > 1)
				{
					echo r_nr2(calcFromKg($v['kg'])) . "" . $w_metric . " x " . $v['reps'];
				}
			}
		}
		else
		{
			// If marked as training
			if($BLOG['meet'] == 0)
			{
				// If a lift fail
				if($v['kg'] > 0 && $v['reps'] == 0)
				{
					if($USER->getShowWeightchange() == 1)
					{
						// Display set with red color
					echo "<span style='color: red;'><div style='float: left; clear: right;'><img src='img/bomb.png' alt='bomb' /></div>" . $v['reps'] . " x " . r_nr2(calcFromKg($v['kg'])) . "" . $w_metric . "</span> ";
					
						// Display RPE
						if($v['rpe'] > 0)
						{
							echo "<span style='color: red;'> @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: red;' rel='prettyPhoto'>RPE</a></span> ";
						}
					
					}
					else
					{
						// Display set with red color
						echo "<span style='color: red;'>" . $v['reps'] . " x " . r_nr2(calcFromKg($v['kg'])) . "" . $w_metric . "</span> ";
						
						// Display RPE
						if($v['rpe'] > 0)
						{
							echo "<span style='color: red;'> @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: red;' rel='prettyPhoto'>RPE</a></span> ";
						}
					}
				}
				elseif($v['reps'] >= 1)
				{
					// Check if the user wants to show weightchanges
					if($USER->getShowWeightchange() == 1)
					{
						// Find the first set
						$check_first_set = checkIfWeightChangeOnSetsIsFirstSet($val['id'],$v['exercise_id']);
						
						if($check_first_set != $v['id'])
						{
								// Lifted at previous set
								$prev_weight = checkWeightChangeOnSets($val['id'],$v['id'],$v['exercise_id']);
								
								// Difference from the previous set
								$diff_prev = r_nr2(calcFromKg($v['kg']))-r_nr2(calcFromKg($prev_weight));
								
								// Display increase or deacrease
								if($diff_prev == 0)
								{
									// Same weight
									echo "<span style='color: lightblue; font-size: 0.8em;'><div style='float: left; clear: right;'><img src='img/arrow_right_blue.png' alt='same' /></div></span> ";
								}
								elseif($diff_prev > 0)
								{
									// Increase
									echo "<span style='color: green; font-size: 0.8em;'><div style='float: left; clear: right;'><img src='img/arrow_up_green.png' alt='increase' /></div>+" . $diff_prev . $w_metric ."</span> ";
								}
								elseif($diff_prev < 0)
								{
									// Deacrease
									echo "<span style='color: red; font-size: 0.8em;'><div style='float: left; clear: right;'><img src='img/arrow_down_red.png' alt='decrease' /></div>" . substr_replace($diff_prev,"", 0,0) . $w_metric ."</span> "; 
								}
						}
						else
						{
							// First set
							echo "<span style='color: lightblue; font-size: 0.8em;'><div style='float: left; clear: right;'><img src='img/arrow_right_green.png' alt='first' /></div></span> ";
						}
					}
					// Display set with null kg only repetitions
					if($v['kg'] == 0 && $v['type'] == "")
					{
						echo $v['reps'] . " "; 
						if($v['reps'] == 1) 
						{ 
							echo translate('repetition'); 
							if($v['rpe'] > 0)
							{
								echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
							}
						}
						elseif($v['reps'] > 1)
						{
							echo translate('repetitions');
							if($v['rpe'] > 0)
							{
								echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
							}
						}
					}
					// Display normal set
					if($v['type'] == "")
					{
						echo "" . $v['reps'] . " x " . r_nr2(calcFromKg($v['kg'])) . "" . $w_metric . "";
						
						// Display RPE
						if($v['rpe'] > 0)
						{
							echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
						}
					}
					// Display dropset
					elseif($v['type'] == "dropset")
					{
						$checkset = checkPreviouesSet($val['id'], $v['id'], $v['type_nr'], $v['exercise_id']);
						$checkset2 = checkPreviouesSet2($val['id'], $v['id'], $v['type_nr'], $v['exercise_id']);
						$checkset3 = checkPreviouesSet3($val['id'], $v['id'], $v['type_nr'], $v['exercise_id']);
						$checkset4 = checkPreviouesSet4($val['id'], $v['id'], $v['type_nr'], $v['exercise_id']);
						$checkset5 = checkPreviouesSet5($val['id'], $v['id'], $v['type_nr'], $v['exercise_id']);
												
						if($checkset == "dropset")
						{
							echo "<span style='padding-left:8px'></span>";
						}
						if($checkset2 == "dropset")
						{
							echo "<span style='padding-left:8px'></span>";
						}
						if($checkset3 == "dropset")
						{
							echo "<span style='padding-left:8px'></span>";
						}
						if($checkset4 == "dropset")
						{
							echo "<span style='padding-left:8px'></span>";
						}
						if($checkset5 == "dropset")
						{
							echo "<span style='padding-left:8px'></span>";
						}
						
						echo "" . $v['reps'] . " x " . r_nr2(calcFromKg($v['kg'])) . "" . $w_metric;
						
						// Display RPE
						if($v['rpe'] > 0)
						{
							echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
						}
						
						echo" <i>(" . translate('dropset') . ""; if($v['type_nr'] != 0) { echo " " . $v['type_nr']; } echo ")</i>";
					}
					// Display superset with 0 kg
					elseif($v['type'] == "superset" && $v['kg'] == 0)
					{
					echo $v['reps'] . " "; 
					
						if($v['reps'] == 1) 
						{ 
							echo translate('repetition');
							
							// Display RPE
							if($v['rpe'] > 0)
							{
								echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
							}
							
							echo " <i>(" . translate('superset') . ""; if($v['type_nr'] != 0) { echo " " . $v['type_nr']; } echo ")</i> "; 
						}
						elseif($v['reps'] > 1)
						{
							echo translate('repetitions');
							
							// Display RPE
							if($v['rpe'] > 0)
							{
								echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
							}
							
							echo " <i>(" . translate('superset') . ""; if($v['type_nr'] != 0) { echo " " . $v['type_nr']; } echo ")</i> ";
						}
					}
					// Display normal superset
					elseif($v['type'] == "superset")
					{
						echo "" . $v['reps'] . " x " . r_nr2(calcFromKg($v['kg'])) . "" . $w_metric;
						
						// Display RPE
						if($v['rpe'] > 0)
						{
							echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
						}
						
						echo " <i>(" . translate('superset') . ""; if($v['type_nr'] != 0) { echo " " . $v['type_nr']; } echo ")</i> ";
					}
				}
			}
			elseif($BLOG['meet'] == 1 || $BLOG['meet'] == 3)
			{
				if($v['reps'] == 1)
				{
					echo r_nr2(calcFromKg($v['kg'])) . "" . $w_metric;
				}
				elseif($v['reps'] == 0)
				{
					echo "<span style='text-decoration: line-through;'>" . r_nr2(calcFromKg($v['kg'])) . "" . $w_metric . "</span>";
				}
				elseif($v['reps'] > 1)
				{
					echo $v['reps'] . " x " .  r_nr2(calcFromKg($v['kg'])) . "" . $w_metric . " ";
				}
			}
		}
		
		// Get video if included
		if($v['url'] != "")
		{
		echo " <a href='" . $v['url'] . "' rel='prettyPhoto'><img alt='". translate('show_video') ."' title='". translate('show_video') ."' src='img/video.png' /></a>";
		}
		
		//Check if its a new pr
			if($v['reps'] >= 1)
			{
				
			$currentpr = checkIfNewPr($v['kg'], $v['reps'], $v['exercise_id'], $BLOG['date'], $U_PROFILE->getId(), $BLOG['meet']);
			$currentprtid = checkIfNewPrTid($v['kg'], $v['reps'], $v['exercise_id'], $BLOG['date'], $U_PROFILE->getId(), $BLOG['meet']);
			$datecurrentpr = checkIfNewPrDate($v['kg'], $v['reps'], $v['exercise_id'], $BLOG['date'], $U_PROFILE->getId(), $BLOG['meet']);
				
				// Check if training or meet and if any lift is found
				if($currentpr != 0 && $currentpr == $v['kg'])
				{
					if($BLOG['meet'] == 0)
					{
						echo " <img alt='". translate('tiepr') ."' title='". translate('tiepr') ."' src='img/star_silver.png' /><font size='1' style='color:darkgreen;'><a style='color:darkgreen;' href='index.php?action=profile&sub=show&tid=$currentprtid'><b> " . translate('similarpersrecord') . " " . formatDate($datecurrentpr, $dateformat) . "!</b></a></font>";
					}
					elseif($BLOG['meet'] == 1 || $BLOG['meet'] == 3)
					{
						echo " <img alt='". translate('tiepr') ."' title='". translate('tiepr') ."' src='img/star_silver.png' /><font size='1' style='color:darkgreen;'><a style='color:darkgreen;' href='index.php?action=profile&sub=show&tid=$currentprtid'><b> " . translate('similarpersrecordmeet') . " " . formatDate($datecurrentpr, $dateformat) . "!</b></a></font>";
					}
				}
				elseif($currentpr != 0 && $currentpr < $v['kg'])
				{
					$diffkg = $v['kg']-$currentpr;
					if($BLOG['meet'] == 0)
					{
						echo " <img alt='". translate('newpr') ."' title='". translate('newpr') ."' src='img/star.png' /><font size='1' style='color:darkgreen;'><a style='color:darkgreen;' href='index.php?action=profile&sub=show&tid=$currentprtid'><b>" . $diffkg . $w_metric . " " . translate('newpersrecord') . " " . formatDate($datecurrentpr, $dateformat) . "!</b></a></font>";
					}
					elseif($BLOG['meet'] == 1 || $BLOG['meet'] == 3)
					{
						echo " <img alt='". translate('newpr') ."' title='". translate('newpr') ."' src='img/star.png' /><font size='1' style='color:darkgreen;'><a style='color:darkgreen;' href='index.php?action=profile&sub=show&tid=$currentprtid'><b>" . $diffkg . $w_metric . " " . translate('newpersrecordmeet') . " " . formatDate($datecurrentpr, $dateformat) . "!</b></a></font>";
					}
				}
			}
		echo "<br />\n";
	}
	// If LBS i selected
	else
	{
		if($USER->getSortKgReps() == 1)
		{
			// If marked as training
			if($BLOG['meet'] == 0)
			{
				// If a lift fail
				if($v['kg'] > 0 && $v['reps'] == 0)
				{
					if($USER->getShowWeightchange() == 1)
					{
						// Display set with red color
						echo "<span style='color: red;'><div style='float: left; clear: right;'><img src='img/bomb.png' alt='bomb' /></div>" . r_nr(calcFromKg($v['kg'])) . "" . $w_metric . "</span> <span style='color: red;'>x</span> <span style='color: red;'>" . $v['reps'] . " </span> ";
						
						// Display RPE
						if($v['rpe'] > 0)
						{
							echo "<span style='color: red;'> @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: red;' rel='prettyPhoto'>RPE</a></span> ";
						}
					}
					else
					{
						// Display set with red color
						echo "<span style='color: red;'>" . r_nr(calcFromKg($v['kg'])) . "" . $w_metric . "</span> <span style='color: red;'>x</span> <span style='color: red;'>" . $v['reps'] . "</span> ";
						
						// Display RPE
						if($v['rpe'] > 0)
						{
							echo "<span style='color: red;'> @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: red;' rel='prettyPhoto'>RPE</a></span> ";
						}
					}
				}
				elseif($v['reps'] >= 1)
				{
					// Check if the user wants to show weightchanges
					if($USER->getShowWeightchange() == 1)
					{
						// Find the first set
						$check_first_set = checkIfWeightChangeOnSetsIsFirstSet($val['id'],$v['exercise_id']);
						
						if($check_first_set != $v['id'])
						{
								// Lifted at previous set
								$prev_weight = checkWeightChangeOnSets($val['id'],$v['id'],$v['exercise_id']);
								
								// Difference from the previous set
								$diff_prev = r_nr(calcFromKg($v['kg']))-r_nr(calcFromKg($prev_weight));
								
								// Display increase or deacrease
								if($diff_prev == 0)
								{
									// Same weight
									echo "<span style='color: lightblue; font-size: 0.8em;'><div style='float: left; clear: right;'><img src='img/arrow_right_blue.png' alt='same' /></div></span> ";
								}
								elseif($diff_prev > 0)
								{
									// Increase
									echo "<span style='color: green; font-size: 0.8em;'><div style='float: left; clear: right;'><img src='img/arrow_up_green.png' alt='increase' /></div>+" . $diff_prev . $w_metric ."</span> ";
								}
								elseif($diff_prev < 0)
								{
									// Deacrease
									echo "<span style='color: red; font-size: 0.8em;'><div style='float: left; clear: right;'><img src='img/arrow_down_red.png' alt='decrease' /></div>" . substr_replace($diff_prev,"", 0,0) . $w_metric ."</span> "; 
								}
						}
						else
						{
							// First set
							echo "<span style='color: lightblue; font-size: 0.8em;'><div style='float: left; clear: right;'><img src='img/arrow_right_green.png' alt='first' /></div></span> ";
						}
					}
					
					// Display set with null kg only repetitions
					if($v['kg'] == 0 && $v['type'] == "")
					{
						echo $v['reps'] . " "; 
						if($v['reps'] == 1) 
						{ 
							echo translate('repetition'); 
							if($v['rpe'] > 0)
							{
								echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
							}
						}
						elseif($v['reps'] > 1)
						{
							echo translate('repetitions');
							if($v['rpe'] > 0)
							{
								echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
							}
						}
					}
					// Display normal set
					if($v['type'] == "")
					{
						echo "" . r_nr(calcFromKg($v['kg'])) . "" . $w_metric . " x " . $v['reps'] . " ";
						
						// Display RPE
						if($v['rpe'] > 0)
						{
							echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
						}
					}
					// Display dropset
					elseif($v['type'] == "dropset")
					{
						$checkset = checkPreviouesSet($val['id'], $v['id'], $v['type_nr'], $v['exercise_id']);
						$checkset2 = checkPreviouesSet2($val['id'], $v['id'], $v['type_nr'], $v['exercise_id']);
						$checkset3 = checkPreviouesSet3($val['id'], $v['id'], $v['type_nr'], $v['exercise_id']);
						$checkset4 = checkPreviouesSet4($val['id'], $v['id'], $v['type_nr'], $v['exercise_id']);
						$checkset5 = checkPreviouesSet5($val['id'], $v['id'], $v['type_nr'], $v['exercise_id']);
												
						if($checkset == "dropset")
						{
							echo "<span style='padding-left:8px'></span>";
						}
						if($checkset2 == "dropset")
						{
							echo "<span style='padding-left:8px'></span>";
						}
						if($checkset3 == "dropset")
						{
							echo "<span style='padding-left:8px'></span>";
						}
						if($checkset4 == "dropset")
						{
							echo "<span style='padding-left:8px'></span>";
						}
						if($checkset5 == "dropset")
						{
							echo "<span style='padding-left:8px'></span>";
						}
						
						echo "" . r_nr(calcFromKg($v['kg'])) . "" . $w_metric . " x " . $v['reps'];
						
						// Display RPE
						if($v['rpe'] > 0)
						{
							echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
						}
						
						echo " <i>(" . translate('dropset') . ""; if($v['type_nr'] != 0) { echo " " . $v['type_nr']; } echo ")</i>";
					}
					// Display superset with 0 kg
					elseif($v['type'] == "superset" && $v['kg'] == 0)
					{
					echo $v['reps'] . " "; 
					
						if($v['reps'] == 1) 
						{ 
							echo translate('repetition');
							
							// Display RPE
							if($v['rpe'] > 0)
							{
								echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
							}
							
							echo " <i>(" . translate('superset') . ""; if($v['type_nr'] != 0) { echo " " . $v['type_nr']; } echo ")</i> "; 
						}
						elseif($v['reps'] > 1)
						{
							echo translate('repetitions');
							
							// Display RPE
							if($v['rpe'] > 0)
							{
								echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
							}
							
							echo " <i>(" . translate('superset') . ""; if($v['type_nr'] != 0) { echo " " . $v['type_nr']; } echo ")</i> ";
						}
					}
					// Display normal superset
					elseif($v['type'] == "superset")
					{
						echo "" . r_nr(calcFromKg($v['kg'])) . "" . $w_metric . " x " . $v['reps'];
						
						// Display RPE
						if($v['rpe'] > 0)
						{
							echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
						}
						
						echo " <i>(" . translate('superset') . ""; if($v['type_nr'] != 0) { echo " " . $v['type_nr']; } echo ")</i> ";
					}
				}
			}
			// If marked as meet
			elseif($BLOG['meet'] == 1 || $BLOG['meet'] == 3)
			{
				if($v['reps'] == 1)
				{
					echo r_nr(calcFromKg($v['kg'])) . "" . $w_metric;
				}
				elseif($v['reps'] == 0)
				{
					echo "<span style='text-decoration: line-through;'>" . r_nr(calcFromKg($v['kg'])) . "" . $w_metric . "</span>";
				}
				elseif($v['reps'] > 1)
				{
					echo r_nr(calcFromKg($v['kg'])) . "" . $w_metric . " x " . $v['reps'];
				}
			}
		}
		else
		{
			// If marked as training
			if($BLOG['meet'] == 0)
			{
				// If a lift fail
				if($v['kg'] > 0 && $v['reps'] == 0)
				{
					if($USER->getShowWeightchange() == 1)
					{
						// Display set with red color
					echo "<span style='color: red;'><div style='float: left; clear: right;'><img src='img/bomb.png' alt='bomb' /></div>" . $v['reps'] . " x " . r_nr(calcFromKg($v['kg'])) . "" . $w_metric . "</span> ";
					
						// Display RPE
						if($v['rpe'] > 0)
						{
							echo "<span style='color: red;'> @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: red;' rel='prettyPhoto'>RPE</a></span> ";
						}
					
					}
					else
					{
						// Display set with red color
						echo "<span style='color: red;'>" . $v['reps'] . " x " . r_nr(calcFromKg($v['kg'])) . "" . $w_metric . "</span> ";
						
						// Display RPE
						if($v['rpe'] > 0)
						{
							echo "<span style='color: red;'> @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: red;' rel='prettyPhoto'>RPE</a></span> ";
						}
					}
				}
				elseif($v['reps'] >= 1)
				{
					// Check if the user wants to show weightchanges
					if($USER->getShowWeightchange() == 1)
					{
						// Find the first set
						$check_first_set = checkIfWeightChangeOnSetsIsFirstSet($val['id'],$v['exercise_id']);
						
						if($check_first_set != $v['id'])
						{
								// Lifted at previous set

								$prev_weight = checkWeightChangeOnSets($val['id'],$v['id'],$v['exercise_id']);
								
								// Difference from the previous set
								$diff_prev = r_nr(calcFromKg($v['kg']))-r_nr(calcFromKg($prev_weight));
								
								// Display increase or deacrease
								if($diff_prev == 0)
								{
									// Same weight
									echo "<span style='color: lightblue; font-size: 0.8em;'><div style='float: left; clear: right;'><img src='img/arrow_right_blue.png' alt='same' /></div></span> ";
								}
								elseif($diff_prev > 0)
								{
									// Increase
									echo "<span style='color: green; font-size: 0.8em;'><div style='float: left; clear: right;'><img src='img/arrow_up_green.png' alt='increase' /></div>+" . $diff_prev . $w_metric ."</span> ";
								}
								elseif($diff_prev < 0)
								{
									// Deacrease
									echo "<span style='color: red; font-size: 0.8em;'><div style='float: left; clear: right;'><img src='img/arrow_down_red.png' alt='decrease' /></div>" . substr_replace($diff_prev,"", 0,0) . $w_metric ."</span> "; 
								}
						}
						else
						{
							// First set
							echo "<span style='color: lightblue; font-size: 0.8em;'><div style='float: left; clear: right;'><img src='img/arrow_right_green.png' alt='first' /></div></span> ";
						}
					}
					
					// Display set with null kg only repetitions
					if($v['kg'] == 0 && $v['type'] == "")
					{
						echo $v['reps'] . " "; 
						if($v['reps'] == 1) 
						{ 
							echo translate('repetition'); 
							if($v['rpe'] > 0)
							{
								echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
							}
						}
						elseif($v['reps'] > 1)
						{
							echo translate('repetitions');
							if($v['rpe'] > 0)
							{
								echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
							}
						}
					}
					// Display normal set
					if($v['type'] == "")
					{
						echo "" . $v['reps'] . " x " . r_nr(calcFromKg($v['kg'])) . "" . $w_metric . "";
						
						// Display RPE
						if($v['rpe'] > 0)
						{
							echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
						}
					}
					// Display dropset
					elseif($v['type'] == "dropset")
					{
						$checkset = checkPreviouesSet($val['id'], $v['id'], $v['type_nr'], $v['exercise_id']);
						$checkset2 = checkPreviouesSet2($val['id'], $v['id'], $v['type_nr'], $v['exercise_id']);
						$checkset3 = checkPreviouesSet3($val['id'], $v['id'], $v['type_nr'], $v['exercise_id']);
						$checkset4 = checkPreviouesSet4($val['id'], $v['id'], $v['type_nr'], $v['exercise_id']);
						$checkset5 = checkPreviouesSet5($val['id'], $v['id'], $v['type_nr'], $v['exercise_id']);
												
						if($checkset == "dropset")
						{
							echo "<span style='padding-left:8px'></span>";
						}
						if($checkset2 == "dropset")
						{
							echo "<span style='padding-left:8px'></span>";
						}
						if($checkset3 == "dropset")
						{
							echo "<span style='padding-left:8px'></span>";
						}
						if($checkset4 == "dropset")
						{
							echo "<span style='padding-left:8px'></span>";
						}
						if($checkset5 == "dropset")
						{
							echo "<span style='padding-left:8px'></span>";
						}
						
						echo "" . $v['reps'] . " x " . r_nr(calcFromKg($v['kg'])) . "" . $w_metric;
						
						// Display RPE
						if($v['rpe'] > 0)
						{
							echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
						}
						
						echo " <i>(" . translate('dropset') . ""; if($v['type_nr'] != 0) { echo " " . $v['type_nr']; } echo ")</i>";
					}
					// Display superset with 0 kg
					elseif($v['type'] == "superset" && $v['kg'] == 0)
					{
					echo $v['reps'] . " "; 
					
						if($v['reps'] == 1) 
						{ 
							echo translate('repetition');
							
							// Display RPE
							if($v['rpe'] > 0)
							{
								echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
							}
							
							echo " <i>(" . translate('superset') . ""; if($v['type_nr'] != 0) { echo " " . $v['type_nr']; } echo ")</i> "; 
						}
						elseif($v['reps'] > 1)
						{
							echo translate('repetitions');
							
							// Display RPE
							if($v['rpe'] > 0)
							{
								echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
							}
							
							echo " <i>(" . translate('superset') . ""; if($v['type_nr'] != 0) { echo " " . $v['type_nr']; } echo ")</i> ";
						}
					}
					// Display normal superset
					elseif($v['type'] == "superset")
					{
						echo "" . $v['reps'] . " x " . r_nr(calcFromKg($v['kg'])) . "" . $w_metric;
						
						// Display RPE
						if($v['rpe'] > 0)
						{
							echo " @ " . $v['rpe'] . " <a href='./img/rpe.JPG' target='_blank'style='color: #555555;' rel='prettyPhoto'>RPE</a> ";
						}
						
						echo " <i>(" . translate('superset') . ""; if($v['type_nr'] != 0) { echo " " . $v['type_nr']; } echo ")</i> ";
					}
				}
			}
			elseif($BLOG['meet'] == 1 || $BLOG['meet'] == 3)
			{
				if($v['reps'] == 1)
				{
					echo r_nr(calcFromKg($v['kg'])) . "" . $w_metric;
				}
				elseif($v['reps'] == 0)
				{
					echo "<span style='text-decoration: line-through;'>" . r_nr(calcFromKg($v['kg'])) . "" . $w_metric . "</span>";
				}
				elseif($v['reps'] > 1)
				{
					echo $v['reps'] . " x " .  r_nr(calcFromKg($v['kg'])) . "" . $w_metric . " ";
				}
			}
		}
		
		// Get video if included
		if($v['url'] != "")
		{
		echo " <a href='" . $v['url'] . "' rel='prettyPhoto'><img alt='". translate('show_video') ."' title='". translate('show_video') ."' src='img/video.png' /></a>";
		}
		
		//Check if its a new pr
			if($v['reps'] >= 1)
			{
				
			$currentpr = checkIfNewPr($v['kg'], $v['reps'], $v['exercise_id'], $BLOG['date'], $U_PROFILE->getId(), $BLOG['meet']);
			$currentprtid = checkIfNewPrTid($v['kg'], $v['reps'], $v['exercise_id'], $BLOG['date'], $U_PROFILE->getId(), $BLOG['meet']);
			$datecurrentpr = checkIfNewPrDate($v['kg'], $v['reps'], $v['exercise_id'], $BLOG['date'], $U_PROFILE->getId(), $BLOG['meet']);
				
				// Check if training or meet and if any lift is found
				if($currentpr != 0 && $currentpr == $v['kg'])
				{
					if($BLOG['meet'] == 0)
					{
						echo " <img alt='". translate('tiepr') ."' title='". translate('tiepr') ."' src='img/star_silver.png' /><font size='1' style='color:darkgreen;'><a style='color:darkgreen;' href='index.php?action=profile&sub=show&tid=$currentprtid'><b> " . translate('similarpersrecord') . " " . formatDate($datecurrentpr, $dateformat) . "!</b></a></font>";
					}
					elseif($BLOG['meet'] == 1 || $BLOG['meet'] == 3)
					{
						echo " <img alt='". translate('tiepr') ."' title='". translate('tiepr') ."' src='img/star_silver.png' /><font size='1' style='color:darkgreen;'><a style='color:darkgreen;' href='index.php?action=profile&sub=show&tid=$currentprtid'><b> " . translate('similarpersrecordmeet') . " " . formatDate($datecurrentpr, $dateformat) . "!</b></a></font>";
					}
				}
				elseif($currentpr != 0 && $currentpr < $v['kg'])
				{
					$diffkg = $v['kg']-$currentpr;
					if($BLOG['meet'] == 0)
					{
						echo " <img alt='". translate('newpr') ."' title='". translate('newpr') ."' src='img/star.png' /><font size='1' style='color:darkgreen;'><a style='color:darkgreen;' href='index.php?action=profile&sub=show&tid=$currentprtid'><b>" . r_nr(calcFromKg($diffkg)) . $w_metric . " " . translate('newpersrecord') . " " . formatDate($datecurrentpr, $dateformat) . "!</b></a></font>";
					}
					elseif($BLOG['meet'] == 1 || $BLOG['meet'] == 3)
					{
						echo " <img alt='". translate('newpr') ."' title='". translate('newpr') ."' src='img/star.png' /><font size='1' style='color:darkgreen;'><a style='color:darkgreen;' href='index.php?action=profile&sub=show&tid=$currentprtid'><b>" . r_nr(calcFromKg($diffkg)) . $w_metric . " " . translate('newpersrecordmeet') . " " . formatDate($datecurrentpr, $dateformat) . "!</b></a></font>";
					}
				}
			}
		echo "<br />\n";
	}
        }
		}
		if($USER->getShowTrainingInBlog() == 1)
		{
		echo "<br />";
		}
		if($USER->getShowTrainingInBlog() == 0)
		{
		echo "<br />";
		}
        echo $BLOG['comment'];
        ?>
        <br />
       
        <a href="<?php echo $url_to_post; ?>" title="<?php echo translate('postby'); ?> <?php echo $U_PROFILE->getFirstname() . " " . ucf($U_PROFILE->getLastname()); ?>"><?php echo translate('readmore'); ?>..</a>
        
           <?php 
			if($BLOG['category'] != "")
			{
				?>
				<br /><br /><span style="font-size:10px;" class="categories"><?php echo translate('category'); ?>: <a href="index.php?action=profile&amp;cat=<?php echo $BLOG['category']; ?>&amp;id=<?php echo $U_PROFILE->getId(); ?>">
				<?php 
				if($BLOG['category'] == 'uncategorized')
				{
					echo translate($BLOG['category']);
				}
				else
				{
					echo $BLOG['category'];
				}
				?>
				</a></span>
				<?php
            }
            ?>
           

		</div>
		<div class="fixed"></div>
	</div>
</div>
<!-- Show all blog post END-->
<?php
				$showing++;
			}
			$counter++;
		}
		if($counter == 0 && $USER_PROFILE->getId() == $USER->getId())
		{
			echo translate('no_post_added_user');
		}
		elseif($counter == 0 && $USER_PROFILE->getId() != $USER->getId())
		{
		 	echo translate('no_post_added_others');	
		}
		?>
		<!-- Display posts END -->
    
    <!-- Display pagenumber START -->
    
    	<?php
    	$post_text = $LANG['showing_posts'];
    	$post_text = str_replace('VAR1', $showing, $post_text);
    	$post_text = str_replace('VAR2', count($blogs), $post_text);
      if(count($blogs) > $USER_PROFILE->getBlogsPerPage())
      {
        // displayPaging($total, $perPage, $url, $pageId);
		echo "<center>" . $post_text . "<br />";
        displayPaging(count($blogs), $USER->getBlogsPerPage(), $page_url, 'p', '<b>[', ']</b>');
		echo "</center>";
     	}
      ?>
    <!-- Display pagenumber END -->
    
</div>
<!-- Left column END -->

<!-- Right column START -->
<div class="rightcoln"> 

	 <!-- Display about START -->
     <?php 
	 if($USER_PROFILE->getAbout() != "")
	 {
	  ?>
    <b><?php echo translate('about_me'); ?></b>
    <br />
     <?php echo nl2br(wordwrap($USER_PROFILE->getAbout(), 25)); ?>
     <br />
     <?php
	 }
	 ?>
     <!-- Display about END -->
    
    <!-- Display stats START -->
    <br />
    <b><?php echo translate('stats'); ?></b><br />
    <?php echo ucf(translate('lifted')); ?> <b><?php $totalkglifted = total_kg_lifted($USER_PROFILE->getId());?><?php echo $w_metric; ?></b> <?php echo strtolower(translate('totally')); ?>
    <!-- Display stats END -->
    
    <br /><br />
    
    <!-- Display show more stats link START -->
     <a href="index.php?action=profile&amp;sub=stats&amp;id=<?php echo $USER_PROFILE->getId(); ?>"><div style='float: left; clear: right; padding-right: 5px;'><img src='img/graf_bar.png' /></div><?php echo translate('showmorestats'); ?></a>
    <!-- Display show more stats link END -->

<br /><br />
    
     <?php
	 //echo "Id til p�logget bruker: " . $USER->getId() . "<br>"; //P�logget bruker 
	// echo "Id til blogg eiger: " . $USER_PROFILE->getId() . "<br>"; //Blogg eiger
	 $userid = $USER_PROFILE->getId(); //Bruker sine kommentarer
	 
     $view_comments = true;
		if($USER_PROFILE->getShowBlogComments($userid) == 0)
		{
			$view_comments = false;
		}

		if($view_comments && $USER->getId())
		{ // restrict view START
		
			 if(count(getShowBlogComments($userid)) > 0)
			 {
				 echo "<b>" . translate('lastcomments') . "</b><br>";
				 foreach(getShowBlogComments($userid) as $key => $val)
				 {
					 $U_PROFILE = new User('id', $val['user_id']);
					 echo "<a href='index.php?action=profile&amp;sub=show&amp;tid=" . $val['post_id'] . "' title='" . translate('commentfrom') . " " . $U_PROFILE->getFirstname() . " " . $U_PROFILE->getLastname() . " (" . translate(ucf(getCountryName($U_PROFILE->getCountry()))) . ", " . formatDate($val['date'], '') . ")'>" . htmlspecialchars(substr($val['comment'], 0, 21))."..</a><br>";
				 }
				 echo "<br>";
			 }
		 
		}
		?>
  	
    
    <!-- Display archive collapsble START -->
    <b><?php echo translate('archive'); ?></b><br />
    <?php
	if(count($archive_list) > 0)
	{
		foreach($archive_list as $year_key => $year_list)
		{
			$counter = 0;
			foreach($year_list as $month_key => $month_list)
			{
				$counter += count($month_list);
			}
			echo "<span id=\"archive_" . $year_key . "_text\"><a href=\"javascript:void(0);\" title='". $year_key .", ". $counter ." ". translate('posts') ."' onclick=\"nav_list('" . $year_key . "', ''); return false;\"><img src=\"img/arrow.gif\" />" . $year_key . "</a></span> (" . $counter .  ")<br />
			<div id=\"archive_" . $year_key . "\" style=\"display: none;\">";
			
			foreach($year_list as $month_key => $month_list)
			{
				echo "&nbsp; <span id=\"archive_" . $year_key . "_" . ($month_key + 1) . "_text\"><a href=\"javascript:void(0);\" title='" . ucf(translate($MONTHS[$month_key])) . ", " . count($month_list) . " ". translate('posts') ."' onclick=\"nav_list('" . $year_key . "', '" . ($month_key + 1) . "'); return false;\"><img src=\"img/arrow.gif\" />" . ucf(translate($MONTHS[$month_key])) . "</a></span> (" . count($month_list) .  ")<br />
				<div id=\"archive_" . $year_key . "_" . ($month_key + 1) . "\" style=\"display: none;\">";
				foreach($month_list as $k => $v)
				{
					$arch_date = @date($CONFIG['date_format_blogarchive'][$USER->getLang()], $v['date']);
					$title = $v['title'];
					if(strlen($title) > 15)
					{
						$title = substr($title, 0, 	15) . "...";
					}
					echo "&nbsp; &nbsp; &nbsp; <a href=\"index.php?action=profile&amp;sub=show&amp;tid=" . $v['id'] . "\" title='" . $v['title'] . ", " . $v['comments'] ." ".  translate('comments') . "'><img src=\"img/page.png\" /> " . ucf($LANG[strtolower(date("l", $v['date']))]) . " " . $arch_date . "</a><br />";
				}
				echo "
				</div>";
			}
			echo "</div>";
		}
	}
	else
	{
		echo translate('no_post_in_archive') . "<br />";
	}
	?>
    <!-- Vise totalt antall innlegg som en string her ! -->
    <!-- Display archive END -->
    
    <br />
    <!-- Display categories  START-->
    <b><?php echo translate('categories'); ?></b><br />
    <?php
	$array_cat = getTrainingCat($USER_PROFILE->getId());
	$showcatunder = translate('showcatunder');
	foreach($array_cat as $val)
					{
						if(getCountTrainingCat($val['cat_name'], $USER_PROFILE->getId()) >= 1)
						{
						echo "<a href='index.php?action=profile&amp;cat=" . $val['cat_name'] . "&amp;id=" . $USER_PROFILE->getId() . "' title='". $showcatunder . " " . $val['cat_name'] ."'>" . substr($val['cat_name'], 0, 20) . "</a> (". getCountTrainingCat($val['cat_name'], $USER_PROFILE->getId()) .")<br>";
						}
					}
						if(getCountTrainingUnCat('uncategorized', $USER_PROFILE->getId()))
						{
						echo "<a href='index.php?action=profile&amp;cat=uncategorized&amp;id=" . $USER_PROFILE->getId() . "' title='". $showcatunder . " " . translate('nocat') . "'>" . translate('nocat') . "</a> (". getCountTrainingUnCat('uncategorized', $USER_PROFILE->getId()) .")";
						}
						if(getCountTrainingUnCat('uncategorized', $USER_PROFILE->getId()) == 0 && getCountTrainingCat($val['cat_name'], $USER_PROFILE->getId()) == 0)
						{
							echo translate('no_post_added_to_cat');	
						}
	?>
    <!-- Display categories END -->
    
    <!-- Display search START -->
<!-- <b><?php //echo translate('searchthisblog'); ?>:</b><br />-->
    <!-- Display search END -->
    
</div>

<div id="view_gym" style="display:none;width:550px;height:500px;overflow:auto;"></div>	 

<!-- Right column END -->
			<?php
		} // restrict view END
			?>
<script type="text/javascript">
	set_default_nav();
</script>
<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){
    $("a[rel^='prettyPhoto']").prettyPhoto();
  });
  
  function open_popup_gym_pending(){
	  	$.post("index2.php",{action:'gym',task:'list_pendding_gyms'}, function(res){
       			$('#view_gym').html(res);
       		 });
						   
	  	$("#view_gym").dialog(
			{ 
				dialogClass: 'dialog',
				width:550,
				height:500,
				 buttons: [
					           {
					               text: "OK",
					               click: function(){ 
					               		$(this).dialog("close"); 
					               	}
					           }
				           ] 
			}
		);	
 	}
</script>
<br />
<?php
unset($USER_PROFILE);
?>